/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN

using namespace std;

int n, u[5333], ans;

inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}

struct land{
	int x1, y1, x2, y2;
	void in() {
		x1 = read();
		y1 = read();
		x2 = read();
		y2 = read();
	}
}l[5333];

int getf(int x) {
	if(u[x] != x) u[x] = getf(u[x]);
	return u[x];
}

bool Union(int a, int b) {
	int fa = getf(a), fb = getf(b);
	if(fa == fb) {
		return false;
	}
	u[fb] = fa;
	return true;
}

bool p_(land a, land b) {
	if(a.x2 < b.x1 - 1 || a.y2 < b.y1 - 1 || a.y1 - 1 > b.y2) return false;
	if(a.x2 == b.x1 - 1) {
		if(a.y2 < b.y1) return false;
		if(a.y1 > b.y2) return false;
	}
	return true;
}

bool cmp(const land &a, const land &b) {
	return a.x1 < b.x1;
} 


int main() {
#ifndef LOCAL
	freopen("jx.in", "r", stdin);
	freopen("jx.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	n = read();
	ans = n;
	
	for(int i = 1; i <= n; i++) {
		u[i] = i;
		l[i].in();
	}
	
	sort(l + 1, l + n + 1, cmp);
	
//	for(int i = 1; i <= n; i++) {
//		printf("%d %d %d %d\n",l[i].x1, l[i].x2, l[i].y1, l[i].y2);
//	}
	
	for(int i = 1; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			if(p_(l[i], l[j]) && Union(i, j)) {
				ans--;
				if(ans == 1){
					printf("1");
					return 0;
				}
			}
		}
	}
	
	printf("%d",ans);
	
	return 0;
}


